﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;  
using MvcVehicleInsurance.Models;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;  

namespace MvcVehicleInsurance.Models
{
      


   
	public partial class Account : INotifyPropertyChanging, INotifyPropertyChanged
	{
        // code tao ra

        private DataClassesVehicleDataContext dc = new DataClassesVehicleDataContext();
        public Account DangnhapAdmin(string Acc_Username, string Acc_Password)
        {
            Account a = new Account();
            try
            {
                a = this.dc.Accounts.Single(ac => ac.Acc_Username.Equals(Acc_Username) && ac.Acc_Password.Equals(Acc_Password));

            }
            catch
            {
                a = null;  
            }

            return a;
        }
        public bool ThemAccount(string Username, string Password,string fullname, string gender, string Address, string Email)
        {
            bool kq = true;
            
            try
            {
                Account ac = new Account();
                ac.Acc_Username = Username;
                ac.Acc_Password = Password;
                ac.Acc_FullName = fullname;
                ac.Acc_Gender = gender;
                
                ac.Acc_Address = Address;
                ac.Acc_Email = Email;

                this.dc.Accounts.InsertOnSubmit(ac);
                this.dc.SubmitChanges();

            }
            catch
            {
                kq = false;
            
            }
            return kq;
                
        }

        public List<Account> Danhsach()
        {
            return this.dc.Accounts.ToList();
        }

        public bool DangNhap(string Username, string Password)
        {
            bool kq = true;
            try
            {
               kq = this.dc.Accounts.Where(ac => ac.Acc_Username.Equals(Username)
               && ac.Acc_Password.Equals(Password)).Count() == 1;
            }
            catch
            {
                kq = false;
            }
            return kq;
        }

        public Account Thongtin(string Username)
        {
            return this.dc.Accounts.Single(ac => ac.Acc_Username.Equals(Username));
        }



       
	}

   

}